package com.ojoin.trade.supplyloan_core.web.service;

import java.util.List;
import java.util.Map;

import com.ojoin.trade.supplyloan_core.web.domain.*;
import org.springframework.data.domain.Pageable;

import com.ojoin.trade.common.exception.BusinessException;
import com.ojoin.trade.common.web.service.BaseService;

public interface TbSlLoanApplicationService extends
		BaseService<TbSlLoanApplication> {

	/**
	 * 新增供应链贷款申请记录 1
	 * 
	 * @param appvo
	 * @throws com.ojoin.trade.common.exception.BusinessException
	 */

	public int insertTbSlApplication(int joinuserid)
			throws BusinessException;

	/**
	 * 更新指定申请记录的申请状态 
	 * 
	 * 合同审核通过 7 保理员
	 * 
	 * @param liveid
	 * @param joinuserid
	 * @param loanstatus
	 * @param clientTs
	 * @throws com.ojoin.trade.common.exception.BusinessException
	 */
	public int updateLoanStatusByIdWithTs(int liveid, int joinuserid, int loanstatus, 
                                    String clientTs) throws BusinessException;

	/**
	 * 更新指定申请记录的申请状态 
	 * 
	 * 合同审核通过 7 保理员
	 * 
	 * @param liveid
	 * @param joinuserid
	 * @param loanstatus
	 * @param mortgage_flag
	 * @param mortgage_info
	 * @param clientTs
	 * @throws com.ojoin.trade.common.exception.BusinessException
	 */
	public int updateLoanStatusAndMortgageByIdWithTs(int liveid, int joinuserid, 
			int idOfTbMerchantUserOfCreditor, int loanstatus, int mortgage_flag, String mortgage_info, 
			String creditEndDate, String taskid, String processid, String clientTs) throws BusinessException;
	
	/**
	 * 更新指定申请记录的申请状态 
	 * 
	 * 已提交实名信息 11 用户 
	 * 已提交平台账号密码 14 用户 
	 * 用户确认授信 5 用户
	 * 
	 * @param joinuserid
	 * @param loanstatus
	 * @throws com.ojoin.trade.common.exception.BusinessException
	 */
	public int updateLoanStatusById(int joinuserid, int loanstatus) throws BusinessException;
	
	/**
	 * 用户提交模糊授信xls及上下游合同
	 * @param joinuserid
	 * @param creditInformation
	 * @param contractFilePath
	 * @throws BusinessException
	 */
	public void updateCreditInformationAndContract(int joinuserid,
			String creditInformation, String contractFilePath) throws BusinessException;
	
	/**
	 * 用户提交模糊授信资料xls 13
	 * @param joinuserid
	 * @param creditInformation
	 * @throws com.ojoin.trade.common.exception.BusinessException
	 */
	public void updateCreditInformation(int joinuserid,
                                        String creditInformation) throws BusinessException;

	
	/**
	 * 拒绝授信
	 * @param liveid
	 * @param joinuserid
	 * @param loanstatus
	 * @param idOfTbMerchantUserOfCreditor 
	 * @param credittype 授信类型 0模糊授信 1精准授信
	 * @param returncredittype 拒绝后返回的授信类型
	 * @param memo 拒绝原因
	 * @param pagets
	 * @return
	 * @throws BusinessException
	 */
	public void refuseCredit(int liveid, int joinuserid, int loanstatus, String credittype, 
			String returncredittype, int idOfTbMerchantUserOfCreditor, String memo,  
			String taskid, String processid, String pagets) throws BusinessException;
	
	/**
	 * 
	 * @param liveid
	 * @param joinuserid
	 * @param loanstatus
	 * @param idOfTbMerchantUserOfCreditor 
	 * @param memo 拒绝原因
	 * @param pagets
	 * @return
	 * @throws BusinessException
	 */
	public void refuseMaterial(int liveid, int joinuserid, int loanstatus, int idOfTbMerchantUserOfCreditor,
			String memo, String taskid, String processid, String pagets) throws BusinessException;
	
	/**
	 * 更新指定申请记录的申请状态 
	 * 
	 * 申请授信失败 4 
	 * 合同审核不通过 8
	 * 
	 * @param liveid
	 * @param joinuserid
	 * @param loanstatus
	 * @param clientTs
	 * @throws com.ojoin.trade.common.exception.BusinessException
	 */

	public int updateLoanStatusAndMemoById(int liveid, int joinuserid,
                                           int loanstatus, String memo, String clientTs)
			throws BusinessException;

	/**
	 * 根据九盈id删除申请记录
	 * 
	 * @param appvo
	 * @throws com.ojoin.trade.common.exception.BusinessException
	 */
	public int deleteTbSlApplicationByJoin(TbSlLoanApplication appvo)
			throws BusinessException;

	/**
	 * 根据join用户查询商户的申请记录
	 * 
	 * @param id_of_tb_merchant_user
	 * @return
	 * @throws com.ojoin.trade.common.exception.BusinessException
	 */
	public TbSlLoanApplication queryTbSlApplicationByJoinId(
            int id_of_tb_merchant_user) throws BusinessException;

	/**
	 * 查询所有的商户的申请记录
	 * 
	 * @return
	 * @throws com.ojoin.trade.common.exception.BusinessException
	 */
	public List<TbSlLoanApplicationInfoVO> queryAllTbSlApplication()
			throws BusinessException;

	/**
	 * 查询id查询商户的申请记录
	 * 
	 * @return
	 * @throws com.ojoin.trade.common.exception.BusinessException
	 */
	public TbSlLoanApplication queryTbSlApplicationByID(int id)
			throws BusinessException;

	/**
	 * 2 模糊授信 融资折扣-discount 融资日利率-rate 融资手续费率-fee 最高融资额度-max_amount
	 * 最长放款期限-loan_period 展期手续费率-renewed_fee 展期日利率-renewed_rate 罚息日利率-penalty
	 * 合同有效期-credit_end_date
	 */
	public void updateVagueCredit(TbSlLoanApplication vo, String taskid, String processid)
			throws BusinessException;
	
	/**
	 * 3 精准授信
	 * @param shortname
	 * @param operatorJoinuserid
	 * @param liveid
	 * @param joinuserid
	 * @param loan_period
	 * @param credit_end_date
	 * @param renewed_servicefee
	 * @param renewed_fee
	 * @param renewed_rate
	 * @param penalty
	 * @param clientTs
	 * @throws com.ojoin.trade.common.exception.BusinessException
	 */
	public void updatePreciseCredit(String shortname, TbSlLoanApplication vo) throws BusinessException;

	/**
	 * 修改授信
	 * 
	 * @param liveid
	 * @param joinuserid
	 * @param discount
	 * @param rate
	 * @param fee
	 * @param loan_period
	 * @param credit_end_date
	 * @param max_amount
	 * @param renewed_servicefee
	 * @param renewed_fee
	 * @param renewed_rate
	 * @param penalty
	 * @param clientTs
	 * @throws com.ojoin.trade.common.exception.BusinessException
	 */
	public void updateCredit(TbSlLoanApplication vo)
			throws BusinessException;

	/**
	 * 用户提交上下游合同 12
	 * @param joinuserid
	 * @param ContractFilePath
	 * @throws com.ojoin.trade.common.exception.BusinessException
	 */
	public void updateContract(int joinuserid,
                               String contractFilePath) throws BusinessException;

	/**
	 * 用户同意授信，生成保理合同
	 * @param joinuserid
	 * @throws BusinessException
	 */
	public void updateAgreeSLLoanFee(int joinuserid) throws BusinessException;
	
	/**
	 * 生成用户保理合同的下载路径
	 * 
	 * @param id
	 * @param material_download
	 * @throws com.ojoin.trade.common.exception.BusinessException
	 */
	public void updateGenerateMaterial(int id) throws BusinessException;

	/**
	 * 用户同意并提交保理合同 6
	 * @param joinuserid
	 * @param materialFilePath
	 * @param slLoanId
	 * @throws com.ojoin.trade.common.exception.BusinessException
	 */
	public void updateMaterial(int joinuserid, String materialFilePath,int slLoanId)
			throws BusinessException;

	/**
	 * 激活供应链贷款业务
	 * 
	 * @param id
	 * @param material
	 * @param contract
	 * @throws com.ojoin.trade.common.exception.BusinessException
	 */
	public void updateActiveSlLoan(int id, String material, String contract)
			throws BusinessException;

	public long getCreditExpiredDays(int id_of_tb_merchant_user)
			throws BusinessException;

	/**
	 * 查询后台管理员代办任务列表
	 * 
	 * @return
	 * @throws com.ojoin.trade.common.exception.BusinessException
	 */
	public List<TbSLLoanTodoTaskVO> queryAdminUserTodoTaskList()
			throws BusinessException;

	/**
	 * 查询保理员代办任务列表
	 * 
	 * @return
	 * @throws com.ojoin.trade.common.exception.BusinessException
	 */
	public List<TbSLLoanTodoTaskVO> queryOperatorTodoTaskList()
			throws BusinessException;

	/**
	 * 根据状态查询供应链贷申请记录
	 * 
	 * @return
	 * @throws com.ojoin.trade.common.exception.BusinessException
	 */

	public List<TbSlLoanApplicationInfoVO> querySLLoanAppInfoListByStatus(
            int loanstatus, Pageable page) throws BusinessException;
	
	
	public List<TbSlLoanApplicationInfoVO> queryCreditedSLLoanAppInfoList(
            int loanstatus, Pageable page) throws BusinessException;
	

	public List<TbSlLoanApplicationStatVO> querySlLoanApplyStatListByStatus(
            int loanstatus, int joinuserid, Pageable page) throws BusinessException;
	
	
	/**
	 * 生成供应链贷融资申请书
	 * @param joinuserid
	 * @param bankacc
	 * @param amount
	 * @param targetPDFFileFolder
	 * @return 
	 * String[] 0 生成的pdf路径  1贷款编号
	 * @throws com.ojoin.trade.common.exception.BusinessException
	 */
	public String[] generateSLLoanApplyFile(int joinuserid, Integer bankacc, List<TbSlLoanCreditLog> creditlogList, String targetPDFFileFolder) throws BusinessException;

   public Long getCreditExpireDays(int joinid)throws BusinessException;
   
   /**
    * 查询指定九盈用户的全部授信信息（包括通用信息和各平台授信信息）
    * @param joinuserid
    * @return
    * @throws BusinessException
    */
   public TbSlLoanCreditAggVO selectAllSLLoanCreditAggVOByJoinID(int joinuserid) throws BusinessException;

   /**
    * 更新九盈用户的全部授信信息（包括通用信息和各平台授信信息）
    * @param aggvo
    * @throws BusinessException
    */
   public void saveSLLoanCreditAggVO(TbSlLoanCreditAggVO aggvo, String taskid, String processid) throws BusinessException;
   
   /**
    * 生成付款通知书
    * @param joinuserid
    * @param creditlogid
    * @param procInsId
    * @return
    * @throws BusinessException
    */
   public String generateSLPaymentOrder(int joinuserid, int creditlogid, String procInsId) throws BusinessException;

   /**
    * 生成展期付款申请单
    * @param joinuserid
    * @param creditlogid
    * @return
    * @throws BusinessException
    */
   public String generateSLRenewedApply(int joinuserid, int creditlogid) throws BusinessException;

    public SlCreditRenewedVo queryRenewedInfoByCredit(Integer id,Integer joinid)throws BusinessException;


    public String queryMerNameByJoinid(int joinid) throws BusinessException;


    public Map<String,Object> initProcessRole(int id)throws BusinessException;
    
    public Map<String, Object> initProcessRoleByAll() throws BusinessException;
    /**
	 * 更新用户的抵押情况
	 * @param joinuserid
	 * @param mortgage_flag
	 * @param mortgage_info
	 * @throws com.ojoin.trade.common.exception.BusinessException
	 */
	public void updateMortgageInfo(int joinuserid,
										int mortgage_flag, 
                                        String mortgage_info) throws BusinessException;
	
	public void riskCreditRefuse(int liveid, int joinuserid, int idOfTbMerchantUserOfCreditor, 
			String memo, String taskid, String processid, String pagets) throws BusinessException;
			
	public void riskCreditPassed(int liveid, int joinuserid, 
			int idOfTbMerchantUserOfCreditor, String taskid, String processid, String pagets) throws BusinessException;

    public void queryNeedMessage() throws BusinessException;
    
    public String querySLLoanAppProcInstIdById(int id) throws BusinessException;
    
    public void updateLoanStatusAndProcessStatus(Integer credittype, int joinuserid, int slloanid, 
    		List<TbSlPlatformUser> entitys) throws BusinessException;


  public  List<TbApplicationExpireVo> queryApplicationExpireForOperator(Pageable page)throws BusinessException;

    
    /**
     * 更新营业执照 有效期
     * @param joinuserid
     * @param expiredDate
     * @throws BusinessException
     */
	public void updateYYZZexpiredDate(int joinuserid,String expiredDate) throws BusinessException;

	
	/**
     * 更新保理合同 有效期
     * @param joinuserid
     * @param expiredDate
     * @throws BusinessException
     */
	public void updateBLHTexpiredDate(int joinuserid,String expiredDate) throws BusinessException;


}